package com.atguigu.gulimall.order.controller;

import cn.hutool.core.util.IdUtil;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author : Jungle
 * @Description :
 */
@Slf4j
@RestController
public class RabbitController {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @GetMapping("/sendMq")
    public String sendMq(@RequestParam(value = "num",defaultValue = "10") Integer num) {
        for (int i = 0; i < 10; i++) {
            CorrelationData correlationData = new CorrelationData(IdUtil.fastSimpleUUID());
            //if (i % 2 == 0) {
                OrderReturnReasonEntity reasonEntity = new OrderReturnReasonEntity();
                reasonEntity.setId(Long.valueOf("" + i));
                reasonEntity.setCreateTime(new Date());
                reasonEntity.setName("哈哈" + i);
                rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", reasonEntity,
                        correlationData);
                log.info("消息发送完成==>{}", reasonEntity);
            //} else {
            //    OrderEntity orderEntity = new OrderEntity();
            //    orderEntity.setOrderSn(IdUtil.fastSimpleUUID());
            //    rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", orderEntity, correlationData);
            //}
        }
        return "Ok";
    }

}
